package nth.bananas.game;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nth.bananas.solving.Letter;

/**
 * This will definitely be reworked when more settings are added.
 * @author Nick Heiner
 *
 */
public class PieceCounts {
	
	private Map<Letter, Integer> counts = new HashMap<Letter, Integer>(23); // mapping of letters to their frequencies

	public Map<Letter, Integer> getCounts() {
		return counts;
	}
	
	public final static PieceCounts EMPTY_PIECE_COUNTS = new PieceCounts(); // using this to initialize a GameMaster will result in instant Bananas time 
	
	private PieceCounts() {
		
	}

	public PieceCounts(String input) {
		Xml config = new Xml(input, "settings");
		
		List<Xml> children = config.child("letterCounts").children("letter");
		
		for (Xml item : children) {
			counts.put(Letter.valueOf(item.string("char").toUpperCase()), item.integer("count"));
		}
		assert counts.size() > 0 : "No piece counts successfully parsed from XML.";
	}

}
